﻿using System;
using System.CommandLine;
using System.IO;

namespace DemoCommandLine
{
    internal class Cat
    {
        public Cat(RootCommand rootCmd)
        {
            var filePath = new Argument<string>(name: "file");
            filePath.SetDefaultValue("");
            var subCom = new Command("cat", "print file content") { filePath };
            subCom.SetHandler((filePathValue) =>
            {
                if (!File.Exists(filePathValue))
                {
                    Ls.Handle(".", FileOrDir.File);
                    return;
                }
                Console.WriteLine(File.ReadAllText(filePathValue));
            }, filePath);
            rootCmd.Add(subCom);
        }
    }
}
